<?php
/**
 * file twolevelnavcontroller.php
 * Created on 2015-4-16 下午5:26:55 
 * Create by xiweijie
 */
namespace haibao\cms\business\control\pc\channel;

use haibao\cms\business\control\PublicController as PublicControllerBusiness;
class TwoLevelNavController extends ChannelController{

    public function __construct($updateTime = null,$controlId,$isPublish){
        parent::__construct($updateTime,$controlId,$isPublish);
    }
    
    /**
     * 显示模版内容（模版动态数据的绑定和模版输出）
     * @param : String $content
     * @param : Array $controlData;
     */
    public function displayTemplateHtml(){
        $controlData = $this->getParameter(self::$CONTROL_DATA);
        $content = $this->getParameter(self::$CONTROL_CONTENT);
        $path = $this->generateHtmlPath(__CLASS__);
        $autoData = array();
        if($controlData['auto']){
        	foreach($controlData['auto'] as $key=>$val){
        		$resultData =json_decode($val['ParameterValue']);
        		if(isset($resultData->showOrder)){
        			$autoData[$resultData->showOrder] = array('ChannelName'=>$resultData->ChannelName,'ChannelUrl'=>$resultData->ChannelUrl);
        		}else{
        			array_push($autoData,array('ChannelName'=>$resultData->ChannelName,'ChannelUrl'=>$resultData->ChannelUrl));
        		}
        	}
        }

        $channelList = array();
        $countList = 0;
		if(isset($controlData['manual']['site'])){
			$channelList = PublicControllerBusiness::getLowerChannelById($controlData['manual']['site']);
		}
		if($channelList){
			foreach($autoData as $key=>$list){
				$tmpArr = array(0=>$list);
				array_splice($channelList,$key-1,0,$tmpArr);
			}
			$countList = count($channelList)-1;
		}else{
			$channelList = $autoData;
			$countList = count($channelList);
		}
		
		foreach($channelList as $key=>$channel){
			$channelUrl = $channel['ChannelUrl'];
			if(strpos($channelUrl,'http') === false){
				$channel['ChannelUrl'] = '/'.$channelUrl;
				$channelList[$key] = $channel;
			}
		}
		
		
        $this->assign('channelList', $channelList);
        $this->assign('count',$countList);
        $isNewHtml = $this->generateHtml($path,$content);
        $content = $this->getHtml($path);
        return $content;
    }
}